// src/servers/servers.controller.ts
import { Controller, Get, Post, Body } from '@nestjs/common';
import { ServersService } from './servers.service';
import { Server } from '../entities/server.entity';
import { createResponse } from '../common/response.interface';
import type { IResponse } from '../common/response.interface';

@Controller('api/servers')
export class ServersController {
  constructor(private readonly serversService: ServersService) {}

  @Get()
  async findAll(): Promise<IResponse<Server[]>> {
    const servers = await this.serversService.findAll();
    return createResponse(servers);
  }

  @Post()
  async create(
    @Body()
    createServerDto: {
      serverName: string;
      ipAddress?: string;
      location?: string;
    },
  ): Promise<IResponse<Server>> {
    const server = await this.serversService.create(createServerDto);
    return createResponse(server, '服务器创建成功');
  }
}